//
//  MallOrderGoodTableViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/5.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallOrderGoodTableViewCell.h"
#import "OrderGoods.h"

@implementation MallOrderGoodTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    CGSize size1 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(12)];
    
    self.contentView.backgroundColor = UISeparatedColorRGB;
    
    self.pic.frame = CGRectMake(10, 5, 2*SW(9), 2*SW(9));
    
    self.title.font = kUHSystemFontWithSize(12);
    self.title.frame = CGRectMake(self.pic.x+self.pic.width+10, 10, SW(2), size1.height*2);
    
    self.price.font = kUHSystemFontWithSize(12);
    self.price.frame = CGRectMake(self.title.x+self.title.width, 15, SCREEN_WIDTH-self.title.x-self.title.width-10, size1.height);
    self.price.textAlignment = NSTextAlignmentRight;
    
    self.num.font = kUHSystemFontWithSize(10);
    self.num.frame = CGRectMake(self.price.x, self.price.y+self.price.height+5, self.price.width, size1.height);
    self.num.textAlignment = NSTextAlignmentRight;
	
	self.category.text = @"";
	self.spec.text = @"";
}

- (void)setModel:(OrderGoods *)model {
    
    if (_model != model) {
        _model = model;
		
        [self.pic sd_setImageWithURL:[NSURL URLWithString:[model valueForKey:@"photo"][0]] placeholderImage:IMAGE(@"placeHolder")];
        self.title.text = [NSString stringWithFormat:@"%@\n", [model valueForKey:@"title"]];
        if ([model valueForKey:@"selectedSku"]) {
            
            self.price.text = [NSString stringWithFormat:@"￥%.2lf", [[model valueForKey:@"selectedSku"][@"price"] floatValue]/100];
        }
		self.price.text = [NSString stringWithFormat:@"￥%.2lf", (double)model.price/100];
        self.num.text = [NSString stringWithFormat:@"X %@", [model valueForKey:@"quantity"]];
        
        if (model.selectedSpecs.count) {
            NSString *cateName = [model.selectedSpecs[0] valueForKey:@"name"];
            NSString *cateValue = [model.selectedSpecs[0] valueForKey:@"val"];
            self.category.text = [NSString stringWithFormat:@"%@: %@", cateName, cateValue];
            
            if (model.selectedSpecs.count >= 2) {
                NSString *specName = [model.selectedSpecs[1] valueForKey:@"name"];
                NSString *specValue = [model.selectedSpecs[1] valueForKey:@"val"];
                self.spec.text = [NSString stringWithFormat:@"%@: %@", specName, specValue];
            }
        }
       
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
